package com.example.ssss;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.StrictMode;
import android.provider.MediaStore;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.NumberPicker;
import android.widget.TextView;
import android.widget.Toast;

import com.example.ssss.data.dao.UserDao;
import com.example.ssss.data.entity.ShareData;
import com.example.ssss.data.entity.User;

import java.io.File;
import java.util.HashMap;

public class PersonInfoActivity extends AppCompatActivity {

    TextView nameText = null;
    TextView sexText = null;
    TextView heightText = null;
    TextView weightText = null;
    TextView ageText = null;

    @Override
    protected void onStop() {

        //TODO 在这里保存个人信息
        super.onStop();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_person_info);
        //隐藏顶部状态栏
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) { actionBar.hide(); }
        nameText = findViewById(R.id.name);
        sexText = findViewById(R.id.gender);
        heightText = findViewById(R.id.high);
        weightText = findViewById(R.id.tizong);
        ageText = findViewById(R.id.age_num);
        new Thread(() -> {
            UserDao userDao = new UserDao();

            ShareData shareData = (ShareData)getApplicationContext();
            User user = null;
            Message msg = null;
            try {
                user = userDao.findUser(shareData.userId);
                msg = new Message();
                msg.what = 1;
                msg.obj = user;
            } catch (Exception e) {
                e.printStackTrace();
            }
            personInfoHandler.sendMessage(msg);
        }).start();
    }

    @SuppressLint("HandlerLeak")
    final Handler personInfoHandler = new Handler()
    {
        public void handleMessage(Message msg) {
        if(msg.what == 1) {
            User user = (User)msg.obj;
            nameText.setText(user.getUsername());
            sexText.setText(user.getSex());
            weightText.setText(user.getWeight());
            heightText.setText(user.getHigh());
            ageText.setText(user.getAge());
        }
    }
    };

}